﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace HexChessBoard
{
    /// <summary>
    /// A hexagonal tile on the chess board.
    /// </summary>
    sealed public class Tile
    {
        // Tile info
        public int IndexInArray;
        public File file;
        public Rank rank;
        public Tile[] Neighbors;     // the index for neighbors in the 1D array, todo convert to int
        public TileColor color;
        public bool IsWhitePawnStartingTile;
        public bool IsBlackPawnStartingTile;
        
        // Piece info
        // These move with the piece
        public PieceType Piece;
        public PieceColor Side;
        public bool PieceWasPawnOnStartingTile;
        public bool PieceHasMoved;
        public List<Tile> AvailableMoves;
        public bool WasEnPassant;   // the piece that will be capturable by en passant. The tile goes into attackable tiles list.
        public int EnPassantIndex;
        public short AttackedValue; // todo how many opposing pieces can attack this tile
        public short DefendedValue; // todo how many same-side pieces can defend this tile


        // Display info
        private Vector3 position;
        private Matrix modelMatrix;
        public Vector3 Position
        {
            get { return position; }
            set
            {
                position = value;
                modelMatrix = Matrix.CreateTranslation(position); //Matrix.CreateScale(scale) * Matrix.CreateRotationX(rotation.X) * Matrix.CreateRotationY(rotation.Y) * Matrix.CreateRotationZ(rotation.Z) * Matrix.CreateTranslation(position);
            }
        }
        public Matrix ModelMatrix
        {
            get { return modelMatrix; }
            set { modelMatrix = value; }
        }

        public Tile(int p_index, File p_File, Rank p_Rank)
        {
            IndexInArray = p_index;
            file = p_File;
            rank = p_Rank;
            IsWhitePawnStartingTile = false;
            IsBlackPawnStartingTile = false;

            Neighbors = new Tile[6] { null, null, null, null, null, null };
            color = TileColor.Dark;

            Piece = PieceType.None;
            Side = PieceColor.White;
            PieceWasPawnOnStartingTile = false;
            PieceHasMoved = false;
            AvailableMoves = new List<Tile>();
            WasEnPassant = false;
            EnPassantIndex = -1;
            AttackedValue = 0;
            DefendedValue = 0;
        }
    }
}